﻿/// <reference path="../Script/jquery-1.3.2-vsdoc.js">

function request(strParame) {
    var args = new Object();
    var query = location.search.substring(1);

    var pairs = query.split("&"); // Break at ampersand 
    for (var i = 0; i < pairs.length; i++) {
        var pos = pairs[i].indexOf('=');
        if (pos == -1) continue;
        var argname = pairs[i].substring(0, pos);
        var value = pairs[i].substring(pos + 1);
        value = decodeURIComponent(value);
        args[argname] = value;
    }
    return args[strParame];
} 


$(document).ready(function() {
    $("img[id^='ctl00_MainContent_img']").each(function() {
        getnode($(this).attr("id"));
        $("img[id^='ctl00_MainContent_img']").click();
    });

});
function getnode(img) {
    $("#" + img).bind("click", function() {
        var img = $(this);
        var UpperCode = $("#" + img.attr("id").replace("img", "CodeID"));
        var count = UpperCode.attr("ChildCount");
        var tr = $("#" + img.attr("id").replace("img", "tr"));
        var loading = "<tr id=\"loading\"><td class=\"TdContent\"><img src=\"../../images/loading.gif\"/> Loading。。。。。。</td><td class=\"TdContent\"></td><td class=\"TdContent\"></td></tr>";
        tr.after(loading);
        $.getJSON("JCKH_KPBZSZTreeList.ashx", { 'CodeID': UpperCode.attr("CodeID"), 'Count': count, 'Id': img.attr("Id"), 'CK': request("CK") }, function(json) {
            $("#loading").remove();
            $.each(json, function(i, n) {
                $("tr[id^='" + tr.attr("id") + "']:last").after(n.PrintContent);
                //alert(n.PrintContent);
            });
        });
        showtr(img);
    });
}

function showtr(img) {
    img.attr("src", "../../images/Collapse.gif");
    img.unbind("click");
    var imgid = img.attr("id").replace("img", "tr");
    img.bind("click", imgid, function() {
        var shownode = "";
        $("tr[id^='" + imgid + "']").each(function() {

            if ($(this).attr("id") != imgid) {
                //if ($(this).attr("id").length > imgid.length + 8 && $(this).css("display")!="none") {
                //shownode = shownode + $(this).attr("id") + ",";
                //}
                if ($(this).css("display") != "none") {
                    shownode = shownode + $(this).attr("id") + ",";
                }
                $(this).hide();
            }
        });
        img.attr("shownode", shownode);
        hidetr(img);
    });
}

function hidetr(img) {
    img.attr("src", "../../images/Expand.gif");
    img.unbind("click");
    var imgid = img.attr("id").replace("img", "tr");
    img.bind("click", imgid, function() {
        $("tr[id^='" + imgid + "']").each(function() {
            //alert(img.attr("shownode"));
            if ($(this).attr("id") != imgid) {
                if (img.attr("shownode") != "" && $(this).attr("id").length > imgid.length + 8) {
                    if (img.attr("shownode").indexOf($(this).attr("id") + ",") != -1) {
                        $(this).show();
                    }
                }
                else {
                    $(this).show();
                }
            }
        });

        showtr(img);
    });
}

function popWin(selectAction, Title) {
    setTimeout(
                      function() {
                          ymPrompt.win({ message: selectAction,
                              width: 570,
                              height: 520,
                              title: Title,
                              handler: null,
                              maxBtn: true,
                              minBtn: true,
                              iframe: true
                          });
                      }, 50);
    return false;
}

function AddLoad(trid) {
    //    alert(trid);
    //    $("#" + trid).css("background", "#FF99CC");
    $("tr[id^='" + trid + "']").each(function() {
        //$(this).css("background", "#FF99CC");
        //alert($(this).attr("id"));
        if ($(this).attr("id") != trid) {
            $(this).remove();
        }
    });
    var img = $("img[id='" + trid.replace("tr", "img") + "']");
    if (img.attr("id") == undefined || img.attr("id") == null) {
        var td = $("#" + trid.replace("tr", "td"));
        //alert(td.attr("id"));
        var expand = "<img src=\"../../images/Expand.gif\" id=\"" + trid.replace("tr", "img") + "\" style=\"height: 9px;width: 9px;cursor:pointer;padding-left:1px;\" />";
        td.text("");
        td.removeAttr("class");
        td.append(expand);
        td = td.next();
        td.attr("class", "Right_Horizontal");
        img = $("img[id='" + trid.replace("tr", "img") + "']");
    }
    else {
        img.click();
    }

    var UpperCode = $("#" + trid.replace("tr", "CodeID"));
    var count = UpperCode.attr("ChildCount");
    var tr = $("#" + trid);
    var loading = "<tr id=\"loading\"><td class=\"TdContent\"><img src=\"../../images/loading.gif\"/> Loading。。。。。。</td><td class=\"TdContent\"></td><td class=\"TdContent\"></td></tr>";
    tr.after(loading);
    $.getJSON("JCKH_KPBZSZTreeList.ashx", { 'CodeID': UpperCode.attr("CodeID"), 'Count': count, 'Id': trid.replace("tr", "img"), 'CK': request("CK") }, function(json) {
        $("#loading").remove();
        $.each(json, function(i, n) {
            $("tr[id^='" + tr.attr("id") + "']:last").after(n.PrintContent);
            //alert(n.PrintContent);
        });
    });
    //updateAJZF();
    showtr(img);
}

function UpdateLoad(trid) {
    var img = $("img[id='" + trid + "']");
    trid = trid.replace("img", "tr");
    $("tr[id^='" + trid + "']").each(function() {
        if ($(this).attr("id") != trid) {
            $(this).remove();
            //alert($(this).attr("id"));
        }
    });
    var UpperCode = $("#" + img.attr("id").replace("img", "CodeID"));
    var count = UpperCode.attr("ChildCount");
    var tr = $("#" + img.attr("id").replace("img", "tr"));
    var loading = "<tr id=\"loading\"><td class=\"TdContent\"><img src=\"../../images/loading.gif\"/> Loading。。。。。。</td><td class=\"TdContent\"></td><td class=\"TdContent\"></td></tr>";
    tr.after(loading);
    $.getJSON("JCKH_KPBZSZTreeList.ashx", { 'CodeID': UpperCode.attr("CodeID"), 'Count': count, 'Id': img.attr("Id"), 'CK': request("CK") }, function(json) {
        $("#loading").remove();
        $.each(json, function(i, n) {
            $("tr[id^='" + tr.attr("id") + "']:last").after(n.PrintContent);
            //alert(n.PrintContent);
        });
    });
    //updateAJZF();
    showtr(img);
}


function updateAJZF() {
    $.getJSON("JCKH_KPBZSZTreeList.ashx", { 'AJCodeID': $("#ctl00_MainContent_AJCodeID").attr("CodeID") },
    function(json) {
        $.each(json, function(i, n) {
            //alert(n.toString());
            $("#ctl00_MainContent_AJCodeID").html(n.toString());
        });
    });
}